import json

# 获取作者名字
# 读取 author.json
with open("author.json", "r", encoding="utf-8") as f:
    authors_data = json.load(f)

# 提取作者名列表（如 ["王伟", "张磊", "刘伟", ...]）
author_names = [item["v"] for item in authors_data]
# authors是列表，里面放的是作者姓名
authors = [author["v"] for authors_data in author_names for author in authors_data]
print(authors)

# data = {
#     "query": "{\"c\":10,\"st\":\"0\",\"f\":[],\"p\":\"\",\"q\":[{\"k\":\"uni_s\",\"a\":1,\"o\":\"\",\"f\":1,\"v\":\"山东大学\"},{\"k\":\"hasAutnam_s\",\"a\":1,\"o\":\"\",\"f\":1,\"v\":\"1111\"}],\"op\":\"AND\",\"s\":[\"nstl\",\"haveAbsAuK:desc\",\"yea:desc\",\"score\"],\"t\":[\"DegreePaper\"]}",
#     "webDisplayId": "11",
#     "sl": "1",
#     "searchWordId": "430098e29f4eb4c47bff8e9129582135",
#     "searchId": "939ec8870b055bdab21f3d9a8338d3ad",
#     "facetRelation": "[{\"id\":\"a3b8c1874555d4f7f0d62f165dfe97f0\",\"sequence\":1,\"field\":\"uni_s\",\"name\":\"院校\",\"value\":\"山东大学\"},{\"id\":\"179a1e094c5a12b0ddc9db606f20b832\",\"sequence\":1,\"field\":\"hasAutnam_s\",\"name\":\"作者\",\"value\":\"1111\"}]",
#     "pageSize": "10",
#     "pageNumber": "1"
# }
#
# for author in authors:
#     # 1. 修改 data["query"]（替换作者名）
#     query_dict = json.loads(data["query"])
#     for item in query_dict["q"]:  # 遍历查询条件
#         if item["k"] == "hasAutnam_s":  # 找到作者字段
#             item["v"] = author  # 替换为当前 author
#     data["query"] = json.dumps(query_dict, ensure_ascii=False)  # 重新转成 JSON 字符串
#     # 2. 修改 data["facetRelation"]（替换作者名）
#     facet_relation_list = json.loads(data["facetRelation"])
#     for item in facet_relation_list:
#         if item["field"] == "hasAutnam_s":  # 找到作者字段
#             item["value"] = author
#     data["facetRelation"] = json.dumps(facet_relation_list, ensure_ascii=False)
#
#     break
